﻿using CommunityToolkit.Mvvm.ComponentModel;
using KxApp.Chart;
using KxApp.Utils;
using LiveCharts;
using System.Collections.ObjectModel;

namespace KxApp.ViewModels
{
    [ExposedService(Lifetime.Singleton)]
    public partial class DeviceViewModel : ObservableObject
    {
        private readonly ApiData apiData;
        private readonly IDeviceService deviceService;
        private readonly ChartService chartService;
        [ObservableProperty]
        private ObservableCollection<KxDevice> devices = new();

        public DeviceViewModel(ApiData apiData, IDeviceService deviceService, ChartService chartService)
        {
            this.apiData = apiData;
            this.deviceService = deviceService;
            this.chartService = chartService;
            this.Devices = deviceService.Devices;

            BarChartSeries = chartService.BarChartSeries;
            BarChartSeries1 = chartService.BarChartSeries1;
            PieValues = chartService.PieValues;
            LineSeries = chartService.LineSeries;
            XAxisLabels = chartService.XAxisLabels;
            ArFlow = chartService.GaugeValue;

            Formatter = value => value.ToString("0.0");
        }

        public SeriesCollection BarChartSeries1 { get; set; } = new();
        public SeriesCollection BarChartSeries { get; set; } = new();
        public SeriesCollection PieValues { get; set; } = new();
        public SeriesCollection LineSeries { get; set; } = new();
        public ObservableCollection<string> XAxisLabels { get; set; } = new();

        [ObservableProperty]
        private Func<double, string> formatter;

        [ObservableProperty]
        private double arFlow = 0;
    }
}
